
<template>
	<view class="s-back">
        <!-- <u-button @click="tologin" type="custom">重新登录</u-button> -->
	</view>
</template>

<script>
let s
	export default {
		name:"subscribe",
    components:{},
		data() {
			return {
			
            }
		},
		async onLoad() {
            s = this
            // if(uni.getStorageSync('h5Token')) {
            //   uni.switchTab({
            //     url:'/pages/index/index'
            //   })
            //   return
            // }
            if (window.location.href.indexOf('code') != -1) {
              localStorage.setItem('isTokening',0)
                var code = window.location.href.match(/code=(\S*)&/)[1]
                
                  var r = await s.$u.api.userWechatUserInfoLogin({
                    code: code,
                 
                })
                if (r) {
                  // 当前这里仅更新头像，不会返回token字段
                  if (r.data?.token) uni.setStorageSync('h5Token',r.data.token)
                  // s.getPageData()
                  // s.getRemindData()
                  uni.switchTab({
                    url:'/pages/my/my'
                  })
                 
                }
                
               
                } else {
                s.getCode()
                }
		},
		mounted() {
			
		},
		
		computed:{
			
		},
		methods: {
      async getPageData(){
				const r = await this.$u.api.configTitle()
				if(r){
					uni.setStorageSync('pageTitle',r.data.title)
				}
			},
			async getRemindData(){
	// 			"zdz_remind": "查出",
    // "welcome": "欢迎"
				const r = await this.$u.api.configRemind()
				if(r){
					uni.setStorageSync('welcome',r.data.welcome)
				}
			},
			async getCode() {
                let appid = ''
               const r = await s.$u.api.configWechat()
               if(r){
                appid = r.data.appid
               }
      const redirectURL = encodeURIComponent(window.location.href)
      const base = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='
      let state = 'STATE'
      
      let scope = 'snsapi_userinfo'
      // let scope = 'snsapi_base'
      // localStorage.setItem('isTokening',1)
      window.location.href =
        base +
        appid +
        '&redirect_uri=' +
        redirectURL +
        '&response_type=code&connect_redirect=1&scope=' +
        scope +
        '&state=' +
        state +
        '#wechat_redirect'
    },
		}
	}
</script>

<style lang="scss" scoped>

</style>
